<template>
	<view>
		<view class="c-box" id="productInquiry">
		    <view class="popup">
		        <view class="frame">
		            <view class="content">
		                <view class="inline">
		                    <view class="item1">
		                        <view class="text">公司</view>
		                        <view>:</view>
		                    </view>
		                    <view class="item2">
		                        <view class="info overflow" v-text="inquiry.company"></view>
		                    </view>
		                </view>
		                <view class="inline">
		                    <view class="item1">
		                        <view class="text">姓名</view>
		                        <view>:</view>
		                    </view>
		                    <view class="item2">
		                        <view class="info overflow" v-text="inquiry.nickName"></view>
		                    </view>
		                </view>
		                <view class="inline">
		                    <view class="item1">
		                        <view class="text">手机号</view>
		                        <view>:</view>
		                    </view>
		                    <view class="item2">
		                        <view class="info overflow" v-text="inquiry.phone"></view>
		                    </view>
		                </view>
		                <view class="inline">
		                    <view class="item1">
		                        <view class="text">询价产品</view>
		                        <view>:</view>
		                    </view>
		                    <view class="item2">
		                        <view class="info overflow" v-text="inquiry.productName"></view>
		                    </view>
		                </view>
		                <view class="inline">
		                    <view class="item1">
		                        <view class="text">备注</view>
		                        <view>:</view>
		                    </view>
		                    <view class="item2">
		                        <view class="info overflow" v-text="inquiry.remarks"></view>
		                    </view>
		                </view>
		                <view class="btn">
		                    <view class="btn-a" href="javascript:void(0);" @click="sendMsg">在线沟通</view>
		                    <view class="btn-a" @click="toCall">电话联系</view>
		                </view>
		            </view>
		        </view>
		    </view>
		</view>
	</view>
</template>

<script>
import inquiryApi from '@/api/inquiryDetail.js';
import commonApi from '@/utils/commonMethod.js';
export default {
	
	data() {
		return {
			inquiry:{},
			inquiryId:'',
			
			currentUser: {},
			startTime:'', //进入页面时间
			endTime:'',//离开页面时间
			currentUrl:'',//当前页面全路径
		}
	},
	async onLoad(options){
		this.inquiryId = options.inquiryId
		await this.getInfoById()
	},
	onShow(){
		
		setTimeout(()=> {
			
			if (getApp().globalData.onShow) {
				getApp().globalData.onShow = 0;
				console.log("demo前后台切换之切到前台")
			}
			else {
				console.log("demo页面被切换显示")
				this.startTime = +new Date();
			}
			
		}, 100);
	},
	onHide(){
		setTimeout(() => {
			var that = this
			if (getApp().globalData.onHide) {
				getApp().globalData.onHide = 0;
				console.log("还在当前页面活动")
			}
			else {
				that.endTime = +new Date();
				console.log("demo页面停留时间：" + (that.endTime - that.startTime))
				var stayTime = Math.round((that.endTime - that.startTime)/1000);
			   //这里获取到页面停留时间stayTime，然后了可以上报了
			   this.saveFootPrint(stayTime);
			}
		}, 100)
	},
	onUnload(){
		setTimeout(() => {
			var that = this
			if (getApp().globalData.onHide) {
				getApp().globalData.onHide = 0;
				console.log("还在当前页面活动")
			}
			else {
				that.endTime = +new Date();
				console.log("demo页面停留时间：" + (that.endTime - that.startTime))
				var stayTime = Math.round((that.endTime - that.startTime)/1000);
			   //这里获取到页面停留时间stayTime，然后了可以上报了
			   this.saveFootPrint(stayTime);
			}
		}, 100)
	},
	methods: {
		saveFootPrint(stayTime){
			commonApi.saveFootPrint(this.currentUser.id,this.startTime,stayTime,this.currentUrl,"询价单详情")
			
		},
		getInfoById(){
			inquiryApi.getInfoById(this.inquiryId).then((res)=>{
				this.inquiry = res.data.nocInquiry
			})
		},
		//在线沟通
		async sendMsg() {
			const res = await commonApi.judgeIfPhone()
			if (res) {
				uni.redirectTo({
					url:"/pages/news/chatDetail/chatDetail?toUserId=" + this.inquiry.userId
				})
			}
		},
		//电话联系
		toCall(){
			commonApi.callUp(this.inquiry.phone)
		}
	}
}
	
</script>

<style>
   .popup {
		display: flex;
		align-items: center;
		flex-direction: column
	}

	.popup .frame {
		width: 100%;
		height: auto;
		background-color: #029e9d;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.popup .frame .title {
		width: 5rem;
		height: 1.5rem;
		line-height: 1.5rem;
		background-color: rgb(2, 158, 157);
		display: flex;
		justify-content: center;
	}

	.popup .frame .title span {
		color: white;
		font-size: 18px;
		font-weight: bold;
	}

	.popup .frame .content {
		width: 100%;
		background-color: white;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.popup .frame .content .btn {
		width: 100%;
		height: 80rpx;
		text-align: center;
		font-size: 27rpx;
		font-weight: normal;
		margin: 45rpx 0 20rpx 0;
		display: flex;
		justify-content: space-evenly;
	}

	.popup .frame .content .btn .btn-a {
		width: 180rpx;
		height: 70rpx;
		line-height: 70rpx;
		color: #fff;
		background: #029e9d;
		border-radius: 25rpx;
		display: inline-block;
	}

	.popup .frame .content .inline {
		height: 65rpx;
		width: 80%;
		display: flex;
		align-items: center;
		font-size: 16px;
		margin-top: 20rpx;
	}

	.popup .frame .content .item1 {
		width: 30%;
		display: inline-flex;
	}

	.popup .frame .content .item2 {
		width: 70%;
		display: inline-flex;
	}

	.popup .frame .content .inline .text {
		width: 100%;
		height: auto;
		text-align-last: justify;
		text-align: justify;
	}

	.popup .frame .content .inline .info {
		width: 100%;
		height: auto;
		font-size: 28rpx;
		text-align: left;
		margin-left: 40rpx;
	}

	.remarks {
		width: 68%;
		height: 3rem;
		padding: 0.2rem 0.4rem;
		background: #f5f5f5;
		line-height: 0.506666rem;
		resize: none;
		font-size: 0.35rem;
	}

	.overflow {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.popup .frame .content .inline input {
		width: 100%;
		height: 0.8rem;
		line-height: 0.8rem;
		border: 0.026666rem solid #029e9d;
		border-radius: 0.16rem;
		margin-left: 0.4rem;
		padding-left: 0.2rem;
		font-size: 0.35rem;
	}

	.popup .frame .content .inline a {
		width: 30%;
		font-size: 0.25rem;
		color: white;
		background: #029e9d;
		border: 1px solid rgb(2, 158, 157);
		border-radius: 0.16rem;
		margin-left: 0.2rem;
		text-align: center;
		height: 0.63rem;
		line-height: 0.63rem;
		margin-top: 0.08rem;
	}
</style>